<template>
  <div class="mod-fii__fiiclasshour">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.like_title" placeholder="名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiiclasshour:save')" type="primary" @click="addOrUpdateHandle2()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiiclasshour:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="orderNum" label="排序" header-align="center" align="center"> </el-table-column>
      <el-table-column prop="title" label="名称" header-align="center" align="center"></el-table-column>
      <!--      <el-table-column prop="details" label="详情" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="target" label="教学目标" header-align="center" align="center"></el-table-column>
      <el-table-column prop="pic" label="封面图" header-align="center" align="center" width="80px">
        <template v-slot="scope">
          <img v-if="scope.row.pic" :src="scope.row.pic" class="avatar" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <!--      <el-table-column prop="createAt" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="creator" label="创建人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="updateAt" label="修改时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="updator" label="修改人" header-align="center" align="center"></el-table-column>-->
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('fii:fiiclasshour:update')" type="text" size="small" @click="addOrUpdateHandle2(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('fii:fiiclasshour:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, nextTick, reactive, toRefs } from "vue";
import AddOrUpdate from "./fiiclasshour-add-or-update.vue";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  props: { courseId: String },
  setup() {
    const state = reactive({
      getDataListURL: "/fii/fiiclasshour/page",
      getDataListIsPage: true,
      exportURL: "/fii/fiiclasshour/export",
      deleteURL: "/fii/fiiclasshour",
      deleteIsBatch: true,

      dataForm: {
        courseId: "",
        eq_courseId: "",
        like_title: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created: function () {
    this.dataForm.courseId = this.courseId as string;
    this.dataForm.eq_courseId = this.courseId as string;
    this.getDataList();
  },
  watch: {
    courseId() {
      this.dataForm.eq_courseId = this.courseId as string;
      this.dataForm.courseId = this.courseId as string;
      this.getDataList();
    }
  },

  methods: {
    addOrUpdateHandle2(id?: string) {
      this.addOrUpdateVisible = true;
      nextTick(() => {
        if (this.addOrUpdate && !this.addOrUpdate.visible) {
          this.addOrUpdate.dataForm.id = id || "";
          this.addOrUpdate.dataForm.courseId = this.dataForm.courseId;
          if (this.total) {
            this.addOrUpdate.dataForm.orderNum = this.total + 1;
          } else {
            this.addOrUpdate.dataForm.orderNum = 1;
          }

          this.addOrUpdate.init();
        }
      });
    }
  }
});
</script>
